package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.DeliveryAddressList;
import com.isunland.managesystem.entity.DeliveryAddressList.DeliveryAddressDetail;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * // 配送货地址
 *
 * @author wu
 */
public class DeliveryAddressDialogFragment extends BaseNetworkDialogFragment {

  public static final String EXTRA_CUSTOMERID = "com.isunland.managesystem.ui.EXTRA_CUSTOMERID";

  private String mCustomerId;

  @Override public void onCreate(Bundle savedInstanceState) {
    mCustomerId = getArguments().getString(EXTRA_CUSTOMERID);
    super.onCreate(savedInstanceState);
  }

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();

    try {

      DeliveryAddressList address = new Gson().fromJson(arg0, DeliveryAddressList.class);

      List<DeliveryAddressDetail> messageDialogs = address.getRows();
      if (messageDialogs == null || messageDialogs.size() == 0) {

        return null;
      }
      for (int i = 0; i < messageDialogs.size(); i++) {
        list.add(new CustomerDialog(messageDialogs.get(i).getAddressDetails(),
            messageDialogs.get(i).getId()));
      }
      return list;
    } catch (Exception e) {

    }

    return list;
  }

  @Override public String getUrl() {
    // Auto-generated method stub
    return ApiConst.URL_ADDRESS_CUSTOMER;
  }

  @Override public HashMap<String, String> getparameters() {

    HashMap<String, String> params = new HashMap<String, String>();
    params.put("mainId", mCustomerId);
    params.put("memberCode", CurrentUser.newInstance(getActivity()).getMemberCode());
    return params;
  }
}
